package wwk.com.android_meilishuo.mvp.presenter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

import wwk.com.android_meilishuo.mvp.model.AssortBiz;
import wwk.com.android_meilishuo.mvp.model.MLSModel;
import wwk.com.android_meilishuo.mvp.view.MLSView;
import wwk.com.android_meilishuo.ui.assort.AllAssortRecyclerAdapter;
import wwk.com.android_meilishuo.ui.assort.Category1AssortRecyclerAdapter;
import wwk.com.android_meilishuo.ui.assort.Category2AssortRecyclerAdapter;
import wwk.com.android_meilishuo.ui.assort.Category3AssortRecyclerAdapter;
import wwk.com.android_meilishuo.ui.assort.TagAssortRecyclerAdapter;
import wwk.com.android_meilishuo.ui.home.bean.InfoBean;
import wwk.com.android_meilishuo.ui.home.bean.ListBean;

/**
 * Created by Administrator on 2017/1/6.
 */

public class AssortPresenter {
    private MLSModel.IAssortBiz mAssortBiz;
    private MLSView.IAssortView mAssortView;

    public AssortPresenter(MLSView.IAssortView mAssortView) {
        this.mAssortBiz = new AssortBiz();
        this.mAssortView = mAssortView;
    }

    public void loadPAssortData(final Context context, final ImageView view_AllTitle, final ImageView view_Tag,
                                final ImageView imageView_Assort_Category1, final ImageView imageView_Assort_Category2, final ImageView imageView_Assort_Category3) {
        mAssortBiz.loadMAssortData(new MLSModel.OnBannerListener() {
            @Override
            public void onBannerSuccess(List<ListBean> list) {
                if (list != null && list.size() != 0) {
                    List<String> stringList = new ArrayList<String>();
                    for (int i = 0; i < list.size(); i++) {
                        stringList.add(list.get(i).getImage());
                    }
                    mAssortView.createBanner(stringList).sendEmptyMessageDelayed(0, 500);
                }
            }

            @Override
            public void onAllAssortSuccess(List<ListBean> list) {
                if (list != null && list.size() != 0) {
                    AllAssortRecyclerAdapter allAdapter = new AllAssortRecyclerAdapter(context, list);
                    mAssortView.toSetAllAdapter(allAdapter);
                }

            }

            @Override
            public void onAllTitletSuccess(InfoBean infoBean) {
                Glide.with(context).load(infoBean.getImage()).into(view_AllTitle);
            }

            @Override
            public void onTagtSuccess(List<ListBean> list) {
                if (list != null && list.size() != 0) {
                    TagAssortRecyclerAdapter tagAdapter = new TagAssortRecyclerAdapter(context, list);
                    mAssortView.toSetTagAdapter(tagAdapter);
                }
            }

            @Override
            public void onTagTitletSuccess(InfoBean infoBean) {
                Glide.with(context).load(infoBean.getImage()).into(view_Tag);
            }

            @Override
            public void onCategory1tSuccess(List<ListBean> list) {
                if (list != null && list.size() != 0) {
                    Category1AssortRecyclerAdapter Category1Adapter = new Category1AssortRecyclerAdapter(context, list);
                    mAssortView.toSetCategory1Adapter(Category1Adapter);
                }
            }

            @Override
            public void onCategory1TitletSuccess(InfoBean infoBean) {
                Glide.with(context).load(infoBean.getImage()).into(imageView_Assort_Category1);
            }

            @Override
            public void onCategory2Success(List<ListBean> list) {
                if (list != null && list.size() != 0) {
                    Category2AssortRecyclerAdapter Category2Adapter = new Category2AssortRecyclerAdapter(context, list);
                    mAssortView.toSetCategory2Adapter(Category2Adapter);
                }
            }

            @Override
            public void onCategory2TitletSuccess(InfoBean infoBean) {
                Glide.with(context).load(infoBean.getImage()).into(imageView_Assort_Category2);

            }

            @Override
            public void onCategory3Success(List<ListBean> list) {
                if (list != null && list.size() != 0) {
                    Category3AssortRecyclerAdapter Category3Adapter = new Category3AssortRecyclerAdapter(context, list);
                    mAssortView.toSetCategory3Adapter(Category3Adapter);
                }
            }

            @Override
            public void onCategory3TitletSuccess(InfoBean infoBean) {
                Glide.with(context).load(infoBean.getImage()).into(imageView_Assort_Category3);

            }

            @Override
            public void onFailed(Exception e) {

            }
        }, context);

    }
}
